package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarAutoPart;


@Repository("carAutoPartDAO")
public class CarAutoPartDAOImpl implements CarAutoPartDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarAutoPart carAutoPart) {
		sessionFactory.getCurrentSession().saveOrUpdate(carAutoPart);
		
	}

	@Override
	public void delete(int id) {
		CarAutoPart carAutoPart = (CarAutoPart) sessionFactory.getCurrentSession().get(CarAutoPart.class, id);
		sessionFactory.getCurrentSession().delete(carAutoPart);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarAutoPart> findAll() {
		
		return (List<CarAutoPart>) sessionFactory.getCurrentSession().createCriteria(CarAutoPart.class).list();
	}

	@Override
	public CarAutoPart findById(int id) {

		return (CarAutoPart) sessionFactory.getCurrentSession().get(CarAutoPart.class, id);
	}

}
